PXC Documentation

PXC Home

Pixel Composer Expression

pre 1.18



Pixel Composer Expression (PCX) is a scripting language used for controlling properties value. Instead of using keyframe animation, you can write a script to control the value of a property.


Using Expression


In the inspector panel. Click on the expression icon, or right click at the property and select "Use expression" to enable/disable expression.




Syntax


Statement


Statements are separated by line, and code block is done with bracklet {}


Returns value


The returns value of the PCX is the last result. So it can be as simple as a single expression: 1 + 1Which will returns the value 2.


Variables


Local variable


Local variable can be define directly:a = 5
a * 2
will returns 10.


Global variable


Global variable are read only, and can be call simply by typing the variable name.


Value variable


value is a reserved variable for getting the value of the property itself. You can use it to get value from keyframe animation or from other node through connection.


Global Structs


There are several global structs that can be used to access other global values.


Variable Description
Project.frame The current frame index
Project.progress Animation progress from 0 - 1
Project.frameTotal Total frames in the animation
Project.fps Current preview speed
Project.time Current preview time (in seconds)
Project.name Current project name
Device.timeSecond Current (real time) second.
Device.timeMinute Current (real time) minute
Device.timeHour Current (real time) hour
Device.timeDay Current (real time) day
Device.timeDayInWee Current (real time) day in a week (0 - 6)
Device.timeMonth Current (real time) month
Device.timeYear Current (real time) year

Constants


Some words are also reserved for mathematical constants.


Variable Value
pi 3.1415926535
e 2.7182818284

String


String can be defined with the double quote "". String support some arithmetic operation and array-like access.s = "Pixel"
s += " Composer"
s[0]
will returns "P".


Array


Array can be created and access with square bracket []. Pixel Composer use zero-indexing for array.a = [ 0, 1, 2, 3, 4, 5 ]
a[2]
will return 2.


Conditions


You can create conditional statement with if, elseif, and else: if(value > 10) {
  1
} elseif(value < 0) {
  -1
} else {
  0
}
This will return -1, 0, 1 based on the junction value.



Functions Reference



sin(radian)


sin



cos(radian)


cos



tan(radian)


tan



dsin(degree)


dsin



dcos(degree)


dcos



dtan(degree)


dtan



arcsin(x)


arcsin



arccos(x)


arccos



arctan(x)


arctan



arctan2(y, x)


arctan2



darcsin(x)


darcsin



darccos(x)


darccos



darctan(x)


darctan



darctan2(y, x)


darctan2



abs(x)


abs



round(x)


round



ceil(x)


ceil



floor(x)


floor



fract(x)


fract



sign(x)


sign



min(x, y)


min



max(x, y)


max



clamp(x, min = 0, max = 1)


clamp



lerp(x, y, amount)


lerp



wiggle(time, frequency, octave = 1, seed = 0)


wiggle



random(min = 0, max = 1)


random



irandom(min = 0, max = 1)


irandom



range(length, start = 0, step = 1)


range



length(value)


length



string(value)


string



number(value)


number



chr(x)


chr



ord(char)


ord



draw(surface, x = 0, y = 0, xs = 1, ys = 1, rot = 0, color = white, alpha = 1)


draw



surface_get_dimension(surface)


surface_get_dimension



surface_get_width(surface)


surface_get_width



surface_get_height(surface)


surface_get_height



color_hex(char)


color_hex



color_rgb(red, green, blue)


color_rgb



color_hsv(red, green, blue)


color_hsv